import { GlobalData } from '../../../store/state'
import { $event } from '../../../utils'
let RecordStatus = require('suit/audio/record_status').RecordStatus
let msgType = require('../msgtype')

Component({
  properties: {
    username: {
      type: Object,
      value: {},
    },
    chatType: {
      type: String,
      value: msgType.chatType.SINGLE_CHAT,
    },
  },
  data: {
    isFullScreen: GlobalData.isFullScreen,
    recordStatus: RecordStatus.HIDE,
    RecordStatus,
    __comps__: {
      main: null,
      emoji: null,
      image: null,
      location: null,
      video: null,
      ptopcall: null,
    },
    isShow: false,
    height: 0,
  },
  methods: {
    showMenu() {
      var flag = this.data.isShow
      this.setData({
        isShow: !flag,
      })
      this.getHight()
    },
    getHight() {
      this.triggerEvent('getHight', null, {})
    },
    // 事件有长度限制：仅限 26 字符
    toggleRecordModal() {
      this.triggerEvent('tapSendAudio', null, {
        bubbles: true,
        composed: true,
      })
    },

    onMakeVideoCall() {
      this.triggerEvent('makeVideoCall', 'single')
    },

    onMakeAudioCall() {
      this.triggerEvent('makeAudioCall', 'single')
    },

    sendVideo() {
      this.data.__comps__.video.sendVideo()
    },

    openCamera() {
      this.data.__comps__.image.openCamera()
    },

    openEmoji() {
      this.data.__comps__.emoji.openEmoji()
    },

    cancelEmoji() {
      this.data.__comps__.emoji.cancelEmoji()
    },

    sendImage() {
      this.data.__comps__.image.sendImage()
    },

    sendLocation() {
      // this.data.__comps__.location.sendLocation();
    },

    emojiAction(evt) {
      this.data.__comps__.main.emojiAction(evt.detail.msg)
    },

    callVideo() {
      console.log('this.data.__comps__.ptopcall', this.data.__comps__.ptopcall)
      this.data.__comps__.ptopcall.show()
    },
  },

  // lifetimes
  created() {
    $event.on('inputEvent', this, (height) => {
      this.setData({ height })
    })
  },
  attached() {},
  moved() {},
  detached() {},
  ready() {
    this.setData({
      isIPX: GlobalData.isIPX,
    })
    this.setData({
      isFullScreen: GlobalData.isFullScreen,
    })
    let comps = this.data.__comps__
    comps.main = this.selectComponent('#chat-suit-main')
    comps.emoji = this.selectComponent('#chat-suit-emoji')
    comps.image = this.selectComponent('#chat-suit-image')
    comps.ptopcall = this.selectComponent('#chat-suit-ptopcall')
    // comps.location = this.selectComponent("#chat-suit-location");
    comps.video = this.selectComponent('#chat-suit-video')
  },
})
